


# 把运算符和数字分割开

s = '13+2/2+4*2-2'

def func(s):
    # 专门存放数字
    nums = []
    # 专门存放运算符
    operations = []
    index = 0
    for i in range(len(s)):
        if s[i] in '+-*/':
            operations.append(s[i])
            nums.append(int(s[index:i]))
            index = i+1
    nums.append(int(s[index:]))
    return nums, operations

def func3(num1, op, num2):
    if op == '*':
        return num1*num2
    elif op == '/':
        return num1/num2
    elif op == '+':
        return num1+num2
    elif op == '-':
        return num1-num2

def func2(nums, operations, cur_op = '*/'):
    n = 0
    while n<len(operations):
        if operations[n] in cur_op:
            nums[n] = func3(nums[n], operations[n], nums[n+1])
            nums.pop(n+1)
            operations.pop(n)
        else:
            n+=1
    return nums, operations

nums, ops = func(s)
print(nums, ops)
nums, ops = func2(nums, ops)
print(nums, ops)
nums, ops = func2(nums, ops, '+-')
print(nums, ops)
print(nums[0])

